import ajax from "./reqBase";
export const baseUrl = 'http://47.108.225.119:8080/';
// export const baseUrl = 'http://127.0.0.1:8081/';
import axios from "axios";

// 登录
export const ReqUserLogin = (data) => ajax(`${baseUrl}/pub/user/login?password=${data.password}&telephone=${data.telephone}&isPc=${data.isPc}`, {}, "POST")
// 根据文章状态获取全部文章信息
export const ReqAllArticle = () => ajax(`${baseUrl}/non_pub/article/manager/getArticleByStatus?identityStatus=1`)
// 根据用户id获取用户信息
export const ReqUserInfoByUserId = (data) => ajax(`${baseUrl}/non_pub/user/getUserInfoById?id=${data.id}`, {}, "POST")
// PC端-新增文章
//export const ReqCreateArticle = (data) => ajax(`${baseUrl}/non_pub/article/createArticle?content=${data.content}&title=${data.title}`, {}, "POST")
export const ReqCreateArticle = function (data) {
    let formdata = new FormData()
    formdata.append('cover', data.cover)
    return new Promise((resolve, reject) => {
        let promise = axios.post(`${baseUrl}/non_pub/article/createArticle?content=${data.content}&title=${data.title}`, formdata, {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: window.sessionStorage.getItem('token')
            }
        })
        promise.then(response => {
            resolve(response.data)
        }).catch(err => {
            reject(err)
        })
    })
}
// pc端删除文章
export const ReqDeleteArticle = (data) => ajax(`${baseUrl}/non_pub/article/deleteArticle?id=${data.id}`, {}, "POST")
// 根据id获取文章点赞
export const ReqGetArticleById = (data) => ajax(`${baseUrl}/non_pub/article/getArticleById?articleId=${data.articleId}`, {}, "POST")
// 获取文章分页
export const ReqGetArticlePage = (data) => ajax(`${baseUrl}/non_pub/article/listArticle`, data)
// 获取根据用户id获取全部文章
export const ReqGetUserArticle = (data) => ajax(`${baseUrl}/non_pub/article/listArticleByUserId`, data)
// 管理员审核文章
export const ReqCheckArticle = (data) => ajax(`${baseUrl}/non_pub/article/manager/checkArticle?articleId=${data.articleId}&status=${data.status}`, {}, "POST")
// PC端-根据状态获取文章
export const ReqGetArticleByStatus = (data) => ajax(`${baseUrl}/non_pub/article/manager/getArticleByStatus?identityStatus=${data.identityStatus}&begin=${data.begin}&num=${data.num}`, {})
// 提交文章审核
export const ReqSubmitIdentity = (data) => ajax(`${baseUrl}/non_pub/article/submitIdentity?articleId=${data.articleId}`, {}, "POST")
// 更新文章
export const ReqUpdateArticle = function (data) {
    let formdata = new FormData()
    formdata.append('cover', data.cover)
    return new Promise((resolve, reject) => {
        let promise = axios.post(`${baseUrl}/non_pub/article/updateArticle?content=${data.content}&id=${data.id}&title=${data.title}`, formdata, {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: window.sessionStorage.getItem('token')
            }
        })
        promise.then(response => {
            resolve(response.data)
        }).catch(err => {
            reject(err)
        })
    })
}

// PC端-管理员接口
// PC端-审核用户认证
export const ReqCheckIdentity = (data) => ajax(`${baseUrl}/non_pub/user/manager/checkIdentity?identifyId=${data.identifyId}&status=${data.status}`, {}, "POST")
// PC端-获取用户信息
export const ReqGetUserList = (data) => ajax(`${baseUrl}/non_pub/user/manager/getUserList`, data)
// 获取用户身份状态信息
export const ReqGetIdentityByStatus = (data) => ajax(`${baseUrl}/non_pub/user/manager/getIdentityByStatus?identityStatus=${data.identityStatus}`, data)

// -------------------------------
// 根据id获取用户信息
export const ReqGetUserInfoById = (data) => ajax(`${baseUrl}/non_pub/user/getUserInfoById?id=${data.id}`, {}, "POST")
// 更新用户信息
export const ReqUpdateUserInfo = (data) => ajax(`${baseUrl}/non_pub/user/updateUserInfo?userId=${data.userId}&desc=${data.desc}&password=${data.password}&sex=${data.sex}&username=${data.username}&status=${data.status}`, {}, "POST")
// 提交认证用户信息
export const ReqSubmitUserIdentity = (data) => ajax(`${baseUrl}/non_pub/user/submitIdentity?education=${data.education}&entranceYear=${data.entranceYear}&profession=${data.profession}&school=${data.school}&stuIDResourceId=${data.stuIDResourceId}`, {}, "POST")
// -------------------------------


//PC端-课程接口
// 获取课程
export const ReqListCourseByUserId = (data) => ajax(`${baseUrl}/non_pub/course/listCourseByUserId?status=${data.status}&begin=${data.begin}&num=${data.num}`, {})
// 增加课程
export const ReqAddCourse = function (data) {
    let formdata = new FormData()
    formdata.append('cover', data.cover)
    return new Promise((resolve, reject) => {
        let promise = axios.post(`${baseUrl}/non_pub/course/addCourse?desc=${data.desc}&name=${data.title}`, formdata, {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: window.sessionStorage.getItem('token')
            }
        })
        promise.then(response => {
            resolve(response.data)
        }).catch(err => {
            reject(err)
        })
    })
}
// 删除课程
export const ReqDeleteCourseById = (data) => ajax(`${baseUrl}/non_pub/course/deleteArticle?id=${data.id}`, {}, "POST")
// 修改课程
export const ReqUpdateCourse = function (data) {
    let formdata = new FormData()
    if (data.hasOwnProperty('tempUploadFile')) {
        formdata.append('cover', data.tempUploadFile)
    }
    formdata.append('cover', data.cover)
    return new Promise((resolve, reject) => {
        let promise = axios.post(`${baseUrl}/non_pub/course/updateCourse?courseId=${data.courseId}&desc=${data.desc}&name=${data.title}`, formdata, {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: window.sessionStorage.getItem('token')
            }
        })
        promise.then(response => {
            resolve(response.data)
        }).catch(err => {
            reject(err)
        })
    })
}
// 提交审核课程
export const ReqSubmitCourseIdentity = (data) => ajax(`${baseUrl}/non_pub/course/submitIdentity?courseId=${data.courseId}`, {}, "POST")

//PC端-课程章节接口
// 根据课程id获取课程和章节
export const ReqGetCourseById = (data) => ajax(`${baseUrl}/non_pub/course/getCourseById?courseId=${data.courseId}`)
// 添加课程章节
export const ReqAddCourseSection = function (data) {
    let formdata = new FormData()
    formdata.append('cover', data.picFile)
    formdata.append('voice ', data.voiceFile)
    return new Promise((resolve, reject) => {
        let promise = axios.post(`${baseUrl}/non_pub/course/addCourseSection?courseId=${data.courseId}&name=${data.name}&order=${data.order}`, formdata, {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: window.sessionStorage.getItem('token')
            }
        })
        promise.then(response => {
            resolve(response.data)
        }).catch(err => {
            reject(err)
        })
    })
}
// PC端-删除课程章节
export const ReqDeleteCourseSectionById = (data) => ajax(`${baseUrl}/non_pub/course/deleteCourseSectionById?sectionId=${data.sectionId}`, {}, "POST")

// PC端-更新课程章节
export const ReqUpdateCourseSection = function (data) {
    let formdata = new FormData()
    formdata.append('cover', data.picFile)
    formdata.append('voice ', data.voiceFile)
    return new Promise((resolve, reject) => {
        let promise = axios.post(`${baseUrl}/non_pub/course/updateCourseSection?sectionId=${data.sectionId}&name=${data.name}&order=${data.order}`, formdata, {
            headers: {
                'Content-Type': 'multipart/form-data',
                token: window.sessionStorage.getItem('token')
            }
        })
        promise.then(response => {
            resolve(response.data)
        }).catch(err => {
            reject(err)
        })
    })
}


// PC端-管理员接口-审核课程信息
export const ReqCheckCourseIdentity = (data) => ajax(`${baseUrl}/non_pub/course/manager/checkIdentity?courseId=${data.courseId}&status=${data.status}`, {}, "POST")
// PC端-管理员接口-获取课程信息
export const ReqGetCourseByStatus = (data) => ajax(`${baseUrl}/non_pub/course/manager/getCourseByStatus?identityStatus=${data.identityStatus}`, data)

// 根据资源id 返回值type-0图片1音频2视频
export const ReqGetResourceById = (data) => ajax(`${baseUrl}/non_pub/resource/getResourceById`, data)
// 资源上传 type-0图片1音频2视频
export const ReqUploadResource = (data) => ajax(`${baseUrl}/non_pub/resource/uploadResource?type=${data.type}`, {}, "POST")
// 根据课程状态获取全部课程信息
// export const ReqAllCourse = (data) => ajax(`${baseUrl}/non_pub/course/manager/getCourseByStatus?identityStatus=${data.identityStatus}`)
// 上传资源
export const UplResource = (data) => ajax(`${baseUrl}/non_pub/resource/uploadResource?type=0`, {}, "POST")
// 上传文章
export const SedArticle = (data) => ajax(`${baseUrl}/non_pub/article/createArticle?content=${data.content}&cover=${data.cover}&title=${data.title}`, {}, "POST")